Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

STY: ignore mypy errors #62482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
mroeschke merged 7 commits into pandas-dev:main from Alvaro-Kothe:fix/mypy-errors
Sep 28, 2025
Merged

Conversation

Copy link
Contributor

@Alvaro-Kothe Alvaro-Kothe commented Sep 27, 2025
edited
Loading

I think this will make the CI green again.

The errors are because of a new version of numpy:

+ numpy==2.3.3
- numpy==2.2.6
+ numpy-typing-compat==20250818.2.3
- numpy-typing-compat==20250818.2.2
Original errors
# mypy
pandas/core/arrays/arrow/_arrow_utils.py:47: error: Unused "type: ignore" comment [unused-ignore]
pandas/_typing.py:87: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/util/hashing.py:327: error: Incompatible types in assignment (expression has type "CategoricalDtype", variable has type "dtype[Any]") [assignment]
pandas/core/util/hashing.py:328: error: Argument 2 to "_simple_new" of "Categorical" has incompatible type "dtype[Any]"; expected "CategoricalDtype" [arg-type]
pandas/core/nanops.py:656: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/array_algos/quantile.py:105: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/algorithms.py:223: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "ExtensionArray") [assignment]
pandas/core/arrays/datetimes.py:807: error: Argument 1 to "view" of "ndarray" has incompatible type "dtype[datetime64[date | int | None]] | DatetimeTZDtype"; expected "dtype[Any] | _HasDType[dtype[Any]]" [arg-type]
pandas/core/arrays/_mixins.py:154: error: Argument "dtype" to "view" of "ndarray" has incompatible type "ExtensionDtype | dtype[Any]"; expected "dtype[Any] | _HasDType[dtype[Any]]" [arg-type]
pandas/core/arrays/string_.py:767: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/arrays/arrow/array.py:660: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/arrays/arrow/array.py:2741: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/arrays/categorical.py:1872: error: Unused "type: ignore" comment [unused-ignore]
pandas/io/pytables.py:3309: error: Unused "type: ignore" comment [unused-ignore]
pandas/io/pytables.py:3309: error: "ExtensionArray" has no attribute "asi8" [attr-defined]
pandas/io/pytables.py:3309: note: Error code "attr-defined" not covered by "type: ignore" comment
pandas/io/pytables.py:3315: error: Unused "type: ignore" comment [unused-ignore]
pandas/io/pytables.py:3315: error: "ExtensionArray" has no attribute "tz" [attr-defined]
pandas/io/pytables.py:3315: note: Error code "attr-defined" not covered by "type: ignore" comment
pandas/io/pytables.py:5199: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/reshape/merge.py:1749: error: Item "ExtensionArray" of "ExtensionArray | Any" has no attribute "all" [union-attr]
pandas/core/reshape/merge.py:1769: error: Item "ExtensionArray" of "ExtensionArray | Any" has no attribute "all" [union-attr]
pandas/core/reshape/encoding.py:362: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/indexers/objects.py:134: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/indexers/objects.py:135: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/indexers/objects.py:405: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/indexers/objects.py:491: error: Unused "type: ignore" comment [unused-ignore]
pandas/core/groupby/groupby.py:1889: error: Unused "type: ignore" comment [unused-ignore]
# pyright
 pandas/core/methods/describe.py:357:19 - error: Type "list[float | NDArray[Any]]" is not assignable to declared type "Sequence[float] | ndarray[_AnyShape, dtype[Any]] | None"
  Type "list[float | NDArray[Any]]" is not assignable to type "Sequence[float] | ndarray[_AnyShape, dtype[Any]] | None"
   "list[float | NDArray[Any]]" is not assignable to "Sequence[float]"
    Type parameter "_T_co@Sequence" is covariant, but "float | NDArray[Any]" is not a subtype of "float"
     Type "float | NDArray[Any]" is not assignable to type "float"
      "ndarray[_AnyShape, dtype[Any]]" is not assignable to "float"
   "list[float | NDArray[Any]]" is not assignable to "ndarray[_AnyShape, dtype[Any]]"
   "list[float | NDArray[Any]]" is not assignable to "None" (reportAssignmentType)
   
 pandas/core/methods/describe.py:360:25 - error: Argument of type "Sequence[float] | ndarray[_AnyShape, dtype[Any]] | None" cannot be assigned to parameter "q" of type "float | Iterable[float]" in function "validate_percentile"
  Type "Sequence[float] | ndarray[_AnyShape, dtype[Any]] | None" is not assignable to type "float | Iterable[float]"
   Type "None" is not assignable to type "float | Iterable[float]"
    "None" is not assignable to "float"
    "None" is incompatible with protocol "Iterable[float]"
     "__iter__" is not present (reportArgumentType)

Copy link
Contributor

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. When we have mypy errors, we try to include text of the mypy error in a comment, so there is a few places where you need to add those.

Comment on lines 3309 to 3315
value.asi8, # type: ignore[attr-defined]
)

node = getattr(self.group, key)
# error: Item "ExtensionArray" of "Union[Any, ExtensionArray]" has no
# attribute "tz"
node._v_attrs.tz = _get_tz(value.tz) # type: ignore[union-attr]
node._v_attrs.tz = _get_tz(value.tz) # type: ignore[attr-defined]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add mypy error in comments (both places)

Copy link
Contributor Author

@Alvaro-Kothe Alvaro-Kothe Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 220 to 225
values = cls._from_sequence(values, dtype=dtype) # type: ignore[assignment]

else:
values = values.astype(dtype, copy=False)
values = values.astype(dtype, copy=False)# type: ignore[assignment]

return values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be fixed as follows. (and you can remove the comments in 218-219). Move the return values statement after line 220 where it says values = cls.from_sequence ... and after line 223 the values = values.astype... statement so that it is no longer at the end of the function.

If mypy still complains on either statement, you need to have a comment in there with the mypy error (as in lines 218-219)

Copy link
Contributor Author

@Alvaro-Kothe Alvaro-Kothe Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know If I've done what you asked, but ended up having these errors:

pandas/core/algorithms.py:232: error: Incompatible return value type (got "ExtensionArray", expected "ndarray[tuple[Any, ...], dtype[Any]]") [return-value]
pandas/core/algorithms.py:234: error: Incompatible return value type (got "ndarray[tuple[Any, ...], dtype[Any]]", expected "ExtensionArray") [return-value]

Check if the changes are correct please

Comment on lines 654 to 656
# error: Unsupported target for indexed assignment ("Union[ndarray[Any, Any],
# datetime64, timedelta64]")
result[axis_mask] = iNaT# type: ignore[index]
result[axis_mask] = iNaT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the comment here since you removed the ignore

Copy link
Contributor Author

@Alvaro-Kothe Alvaro-Kothe Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mroeschke mroeschke added the Typing type annotations, mypy/pyright type checking label Sep 28, 2025
@mroeschke mroeschke added this to the 2.3.3 milestone Sep 28, 2025
@mroeschke mroeschke merged commit e97a56e into pandas-dev:main Sep 28, 2025
47 checks passed
Copy link
Member

Thanks @Alvaro-Kothe

Copy link

lumberbot-app bot commented Sep 28, 2025

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 2.3.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 e97a56e746f8cdeabf7e83ec83455cbf5386c909
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #62482: STY: ignore mypy errors'
  1. Push to a named branch:
git push YOURFORK 2.3.x:auto-backport-of-pr-62482-on-2.3.x
  1. Create a PR against branch 2.3.x, I would have named this PR:

"Backport PR #62482 on branch 2.3.x (STY: ignore mypy errors)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

Copy link
Contributor Author

I don't believe backporting is required because branch 2.3.x does not use the latest version of NumPy.

- numpy<2
mroeschke reacted with thumbs up emoji

Copy link
Contributor

Dr-Irv commented Sep 29, 2025

I don't believe backporting is required because branch 2.3.x does not use the latest version of NumPy.

I'll let @mroeschke comment here, but I think backporting may be required because the CI requires the latest version of numpy. What I'm not sure of is if we run the code checks on the backported branch.

Copy link
Member

Indeed no need to backport (at the moment), the CI build on 2.3.x that runs linting is indeed pinned to numpy<2 as @Alvaro-Kothe mentions, so the typing errors are in general slightly different (and I don't think it is worth the effort to try to align that at this point)

mroeschke reacted with thumbs up emoji

jzwick pushed a commit to jzwick/pandas that referenced this pull request Oct 1, 2025
Co-authored-by: Irv Lustig <irv@princeton.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@Dr-Irv Dr-Irv Dr-Irv requested changes

@mroeschke mroeschke mroeschke approved these changes

@rhshadrach rhshadrach Awaiting requested review from rhshadrach rhshadrach is a code owner

Assignees
No one assigned
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Milestone
3.0
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /